package com.cloud.lan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.lan.api.dto.req.LanBadgeCfgReq;
import com.cloud.lan.dao.LanBadgeCfgMapper;
import com.cloud.lan.entity.base.BaseResponse;
import com.cloud.lan.entity.model.dataobject.LanBadgeCfgDO;
import com.cloud.lan.service.ILanBadgeCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * Created by zhouquan on 2022/5/19.
 * 徽章配置服务.增删改查
 */
@Slf4j
@Service
public class LanBadgeCfgServiceImpl implements ILanBadgeCfgService{

    @Resource
    private LanBadgeCfgMapper lanBadgeCfgMapper;

    @Override
    public BaseResponse<Object> manageList(LanBadgeCfgReq req) {
        log.info("徽章配置.查询列表:{}", req);
        LambdaQueryWrapper<LanBadgeCfgDO> qw = new LambdaQueryWrapper<>();
        qw.orderByDesc(LanBadgeCfgDO::getId);
        Page<LanBadgeCfgDO> page = new Page<>(req.getPageIndex(), req.getPageSize());
        IPage<LanBadgeCfgDO> pageList = lanBadgeCfgMapper.selectPage(page, qw);
        return BaseResponse.success(pageList);
    }

    @Override
    public BaseResponse<Object> add(LanBadgeCfgReq req) {
        log.info("徽章配置.新增:{}", req);
        LanBadgeCfgDO lanBadgeCfgDO = new LanBadgeCfgDO();
        BeanUtil.copyProperties(req, lanBadgeCfgDO);
        lanBadgeCfgMapper.insert(lanBadgeCfgDO);
        return BaseResponse.success();
    }

    @Override
    public BaseResponse<Object> delete(Long id) {
        log.info("徽章配置.删除:{}", id);
        lanBadgeCfgMapper.deleteById(id);
        return BaseResponse.success();
    }

    @Override
    public BaseResponse<Object> update(LanBadgeCfgReq req) {
        log.info("徽章配置.更新:{}", req);
        LanBadgeCfgDO lanBadgeCfgDO = new LanBadgeCfgDO();
        BeanUtil.copyProperties(req, lanBadgeCfgDO);
        lanBadgeCfgMapper.updateById(lanBadgeCfgDO);
        return BaseResponse.success();
    }
}
